package com.easyexcle.demo.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.hutool.core.util.IdUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.easyexcle.demo.easypoi.domain.ExportVo;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class DemoTest {

    /**
     * 糊涂工具包测试 导入
     * @param args
     */
    public static void main(String[] args) {

//        ExcelReader reader = ExcelUtil.getReader("D://moban.xlsx");
//        List<List<Object>> readAll = reader.read();
//       for(List tt:readAll){
//           System.out.println(tt);
//       }
       // 测试easypoi
        List<ExportVo> list=new ArrayList<>();
       for(int i=0;i<100;i++){
           ExportVo exportVo = new ExportVo();
           exportVo.setCode(String.valueOf(i));
           exportVo.setCodeName("张"+i);

           exportVo.setStatus(String.valueOf(i));
           exportVo.setSuijiCode(String.valueOf(i));
           exportVo.setSuijiMan(String.valueOf(i));
           exportVo.setTime(new Date());
           exportVo.setCoreCode(String.valueOf(i));
           list.add(exportVo);

       }
        ExportParams exportParams=new ExportParams(null,"汇总中心报告", ExcelType.XSSF);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, ExportVo.class, list);
        String filePath="D:/test/"+ IdUtil.objectId()+".xlsx";

        try {
            FileOutputStream fileOutputStream = new FileOutputStream(filePath);
            workbook.write(fileOutputStream);
            fileOutputStream.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    /**
     * 参考文章链接
     *  表头添加批注；
     *    https://blog.csdn.net/lxhJava15/article/details/127029625
     *    https://blog.csdn.net/h1192341606/article/details/106378030/
     *    https://blog.csdn.net/weixin_41481806/article/details/127668308
     *
     *  表头下拉框
     *      https://blog.csdn.net/ANewProgrammer/article/details/123404617
     *
     */

    @Test
    public void test3(){
        ExcelReader reader = ExcelUtil.getReader("C:\\Users\\likz\\Desktop\\test.xlsx");
        List<Map<String, Object>> readAll = reader.readAll();
        for(int a=0;a<readAll.size();a++){
            Map<String, Object> map = readAll.get(a);
            if(a==0){
                continue;
            }

        }
        System.out.println("2332");
    }


    public String num(long num){
        // 0 代表前面补充0    只能补0 不能补别的数字,否则会出现前面补空格,
        // 4 代表长度为4
        // d 代表参数为正数型
        String str = String.format("%010d", num);
        return "JSJF4001859909"+str;
    }

}
